<?php 
//接口声明要实现的方法
interface CarContract
{
    public function drive();
}

class LynkCo01 implements CarContract
{
    protected $brand;

    public function __construct($brand)
    {
        $this->brand = $brand;
    }

    public function drive()
    {
        echo "启动{$this->brand}汽车" . '<br/>';
    }
}



abstract class BaseCar implements CarContract
{
    protected $brand;

    public function __construct($brand)
    {
        $this->brand = $brand;
    }

    abstract public function drive();
}

class LynkCo03 extends BaseCar
{
    public function __construct()
    {
        $this->brand = "领克03";
        // parent::__construct($this->brand);
    }

    public function drive()
    {
        echo "启动{$this->brand}汽车" . '<br/>';
    }
}

$lynkCo02 = new LynkCo03();
$lynkCo02->drive();

//通过接口重构测试方法
class TestCar
{
    public function testDrive(CarContract $car)
    {
        $car->drive();
    }
}

$lynkCo01 = new LynkCo01('别克01');
$lynkCo03 = new LynkCo03();

$testCar = new TestCar();
$testCar->testDrive($lynkCo01);
echo "=============" . '<br/>';
$testCar->testDrive($lynkCo03);

echo '<br/>类型运算符<br/>';
var_dump($lynkCo01 instanceof CarContract);
var_dump($lynkCo03 instanceof BaseCar);
var_dump($testCar instanceof CarContract);
var_dump($testCar instanceof BaseCar);